
/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-06-14     wangy       the first version
 */
#include <rtthread.h>
#include <board.h>
#include <sht3x.h>
#include "sth30.h"
#include <string.h>
#include "drv_lcd.h"

/* 开启DEBUG功能 */
#define DBG_ENABLE
#define DBG_LEVEL DBG_LOG
#define DBG_SECTION_NAME "userapp"

#define DBG_COLOR
#include <rtdbg.h>

/* 入口函数 */
void sht30_init_thread_entry(void *parameter)
{
    sht3x_device_t  sht3x_device;

    sht3x_device = sht3x_init("i2c2", 0x44);

    rt_thread_mdelay(100);

    char num[10];
    //lcd_disp_str_en(10, 150, "humidity:",WHITE,GREEN);
    //lcd_disp_str_en(10, 170, "temperature:",WHITE,GREEN);
    while (1)
    {
        if(RT_EOK == sht3x_read_singleshot(sht3x_device))
        {
            memset(num,0,10);
            sprintf(num,"humidity  : %d.%d  ",(int)sht3x_device->humidity,(int)(sht3x_device->humidity * 10) % 10);
            LOG_I("humidity   : %d.%d  ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
            lcd_disp_str_en(10, 150, num,WHITE,GREEN);

            memset(num,0,10);
            sprintf(num,"temperature   : %d.%d  ",(int)sht3x_device->temperature,(int)(sht3x_device->temperature * 10) % 10);
            LOG_I("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
            lcd_disp_str_en(10, 170, num,WHITE,GREEN);
        }
        else
        {
            rt_kprintf("read sht3x fail.\r\n");
            break;
        }
        rt_thread_mdelay(2000);
    }
}
